package demo523;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class Update {
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        Connection connection=SqlConnection.getCon();
        Scanner  scanner=new Scanner(System.in);//从键输入
        System.out.println("请输入用户的id");
        int id=scanner.nextInt();
        System.out.println("请输入用户名");
        String username=scanner.next();

        String sql="update users SET username  =  ?  where id = ?  ";
        PreparedStatement preparedStatement=connection.prepareStatement(sql);
//给问号赋值：
       preparedStatement.setString(1,username);
       preparedStatement.setInt(2,id);
        int i=preparedStatement.executeUpdate();

        if(i>0){
            System.out.println("修改成功");
        }
        else{
            System.out.println("修改失败");
        }


    }
}
